home *** CD-ROM | disk | FTP | other *** search
-
- /*⌐ Copyright 1988-1991 UserLand Software, Inc. All Rights Reserved.*/
-
-
- /*
- bitmaps.c -- routines which manage off-screen bitmaps. In order to use these routines
- the program must call "initbitmaps" before calling anything.
-
- initbitmaps takes a boolean. if false, then all subsequent calls to bitmap routines do
- nothing but return.
- */
-
- #include "appletinternal.h"
- #include "bitmaps.h"
-
-
- BitMap offscreenbitmap, savedbitmap;
-
- Handle bitmapbasehandle;
-
- boolean flbitmapsenabled;
-
- boolean flbitmapopen = false; /*is one open right now?*/
-
-
-
- boolean openbitmap (r, w) Rect r; WindowPtr w; {
-
- register short nrowbytes;
- register long nboxbytes;
- register long sizehandle;
-
- flbitmapopen = false;
-
- if (!flbitmapsenabled) /*application doesn't want any bitmaps*/
- return (false);
-
- nrowbytes = (r.right - r.left + 7) / 8;
-
- if ((nrowbytes % 2) == 1) /*odd number*/
- nrowbytes++;
-
- nboxbytes = (r.bottom - r.top) * nrowbytes;
-
- SetHandleSize (bitmapbasehandle, nboxbytes);
-
- sizehandle = GetHandleSize (bitmapbasehandle);
-
- if (sizehandle < nboxbytes) {
-
- SetHandleSize (bitmapbasehandle, 10L);
-
- return (false);
- }
-
- HLock (bitmapbasehandle);
-
- offscreenbitmap.baseAddr = *bitmapbasehandle;
-
- offscreenbitmap.rowBytes = nrowbytes;
-
- offscreenbitmap.bounds = r;
-
- savedbitmap = (*w).portBits;
-
- CopyBits (&savedbitmap, &offscreenbitmap, &r, &r, srcCopy, nil);
-
- SetPortBits (&offscreenbitmap);
-
- flbitmapopen = true; /*remember in our own local global*/
-
- return (true);
- } /*openbitmap*/
-
-
- void closebitmap (w) WindowPtr w; {
-
- if (flbitmapsenabled && flbitmapopen) {
-
- flbitmapopen = false;
-
- SetPortBits (&savedbitmap);
-
- CopyBits (
- &offscreenbitmap, &((*w).portBits), &offscreenbitmap.bounds,
-
- &offscreenbitmap.bounds, srcCopy, nil);
-
- HUnlock (bitmapbasehandle);
-
- offscreenbitmap.baseAddr = 0;
-
- SetHandleSize (bitmapbasehandle, 10L);
- }
- } /*closebitmap*/
-
-
- void initbitmaps (boolean flbitmaps) {
-
- flbitmapsenabled = flbitmaps;
-
- if (flbitmapsenabled) {
-
- bitmapbasehandle = NewHandle (10L);
-
- offscreenbitmap.baseAddr = 0;
-
- offscreenbitmap.rowBytes = 2;
-
- SetRect (&offscreenbitmap.bounds, 0, 0, 0, 0);
- }
- } /*initbitmaps*/
-
-
-
-